home *** CD-ROM | disk | FTP | other *** search
- Path: news.mel.aone.net.au!Rabbit
- From: biggles@c031.aone.net.au (Biggles Cheung)
- Newsgroups: comp.lang.c++
- Subject: Re: Bucket sort?!?
- Date: Tue, 09 Apr 96 14:14:58 GMT
- Message-ID: <4ke0o6$rqo@news.mel.aone.net.au>
- References: <Pine.SOL.3.91.960407192931.10206A-100000@jove.acs.unt.edu>
- NNTP-Posting-Host: d86-1.cpe.melbourne.aone.net.au
- X-Newsreader: News Xpress 2.0 Beta #0
-
- In article <Pine.SOL.3.91.960407192931.10206A-100000@jove.acs.unt.edu>, Daniel Lee Mccormick <dlm0001@jove.acs.unt.edu> wrote:
- >Hello,
- >I'm new to c++ coding and am having a prob. Could someone please post an
- >example of bucket sorting. I'm reading in from a data file into an array,
- >but I'm stumped on the actual sorting part. Any help would be appreciated.
- >
- >-Daniel
-
- Bucket Sort is the same as _Distribution Sort_, so try looking for
- distribution sort in any reference book.
-
- I just copy the following example from my lecture note, & hope this helps
- (hope this works :-o )...
-
-
- * Sort N records in array a[] whose keys are intergers between 0 and M-1
-
-
- distribution(int a[], int N) {
-
- int i, j, count[M], b[N+1]; /* count[] & b[] are temporary arrays
-
- for (j=0; j<M; j++)
- count[j]= 0; /* init counts
- for (i=1; i<=N; i++)
- count[a[i]]++; /* count no. of each key
- for (j=1; j<M; j++)
- count[j] += count[j-1]; /* compute offsets
- for (i=N; i>=1; i--)
- b[count[a[i]]--] = a[i]; /* sort into b backwardly to ensure stability
- for (i=1; i<=N; i++)
- a[i] = b[i]; /* copy back into original array, i.e. a[]
- }
-
-
- You may find more about Bucket Sort (distribution sort) from ...
-
- Algorithm in C, Robert Sedgewick, Addison Wesley
-
-
- _/\/\/\/\/\___/\/\_________________________/\/\_________________________
- _/\/\____/\/\__________/\/\/\/\___/\/\/\/\_/\/\_____/\/\/\_____/\/\/\/\_
- _/\/\/\/\/\___/\/\___/\/\__/\/\_/\/\__/\/\_/\/\___/\/\/\/\/\_/\/\/\/\___
- _/\/\____/\/\_/\/\_____/\/\/\/\___/\/\/\/\_/\/\___/\/\_____________/\/\_
- _/\/\/\/\/\___/\/\/\_______/\/\_______/\/\_/\/\/\___/\/\/\/\_/\/\/\/\___
- ____________________/\/\/\/\___/\/\/\/\_________________________________
-